#include "KnowledgeCenter.h"
using namespace Branch1;
using namespace DAISY;
template<> KnowledgeCenter* Tools::Singleton<KnowledgeCenter>::_singleton = new KnowledgeCenter();
bool KnowledgeCenter::init()
{
	return true;
}
void KnowledgeCenter::shutDown()
{
	if(!_currOffice)
		_currOffice = 0;
}
bool  KnowledgeCenter::addOffice(const std::string& officeName,Office* office)
{
	std::map<const std::string,Office*>::const_iterator it = _officeMap.find(officeName);
	if(it != _officeMap.end())
		throw DAISY_EXCEPTION(DAISY::Exception::ERR_DUPLICATE_ITEM);
	else
		_officeMap.insert(std::make_pair(officeName,office));
	return true;
}
bool  KnowledgeCenter::removeOffice(const std::string& officeName)
{	 
	std::map<const std::string,Office*>::const_iterator it = _officeMap.find(officeName);
	if(it != _officeMap.end())
		_officeMap.erase(it);
	else
		return false;
	return true;
}
Office*  KnowledgeCenter::getOffice(const std::string& officeName)
{
	std::map<const std::string,Office*>::const_iterator it = _officeMap.find(officeName);
	if(it != _officeMap.end())
		return it->second;
	else
		throw DAISY_EXCEPTION(DAISY::Exception::ERR_ITEM_NOT_FOUND);

}
void  KnowledgeCenter::setCurrOffice(const std::string& officeName)
{
	std::map<const std::string,Office*>::const_iterator it = _officeMap.find(officeName);
	if(it != _officeMap.end())
		_currOffice = it->second;
	else
		throw DAISY_EXCEPTION(DAISY::Exception::ERR_ITEM_NOT_FOUND);
}
Office*  KnowledgeCenter::getCurrOffice()
{
	return _currOffice;
}